﻿using NHibernate.Validator.Constraints;
using TestBat.IModels.Domain;

namespace TestBat.Models.Domain
{
    public class LeafTaskFolder : TaskFolder, ILeafTaskFolder
    {
        /// <summary>
        /// the parent-folder
        /// </summary>
        [NotNull]
        public virtual ITaskFolder Parent
        {
            get { return parent; }
            set
            {
                if (Equals(parent, value))
                    return; // no change needed

                if (parent != null)
                    parent.Children.Remove(this); // remove from old parent

                parent = value;

                if (parent != null)
                    parent.Children.Add(this); // add to new parent's children
            }
        }

        /// <summary>
        /// removes this folder from the parent's collection
        /// this doesn't touch the parent field
        /// </summary>
        public virtual void Detach()
        {
            if (parent != null)
                parent.Children.Remove(this);
        }

        /// <summary>
        /// the parent-folder
        /// </summary>
        private ITaskFolder parent;
    }
}
